package com.demo;

import cn.hutool.core.util.RandomUtil;
import cn.lingyangwl.framework.core.response.Resp;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author shenguangyang
 */
@Api(tags = "demo模块")
@RequestMapping("/demo")
@RestController
public class DemoController {

    @ApiOperation(value = "保存用户数据01")
    @PostMapping("/test1")
    public UserSaveReqDTO test1(@RequestBody UserSaveReqDTO reqDTO) {
        return UserSaveReqDTO.builder().id(reqDTO.getId())
                .password(reqDTO.getPassword()).username(reqDTO.getUsername())
                .age(reqDTO.getAge())
                .build();
    }

    @ApiOperation("保存用户信息02")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "username", value = "名字", required = true, paramType = "path"),
            @ApiImplicitParam(name = "age", dataType = "int", value = "年龄", required = true, paramType = "query")
    })
    @PostMapping("/test2/{username}")
    public UserSaveReqDTO test2(@PathVariable("username") String name, @RequestParam("age") Integer age) {
        return UserSaveReqDTO.builder().id(RandomUtil.randomNumbers(12))
                .username(name)
                .age(age)
                .build();
    }

    @ApiOperation(value = "修改密码", notes = "方法的备注说明，如果有可以写在这里")
    @ApiResponses({
            @ApiResponse(code = 400, message = "请求参数没填好"),
            @ApiResponse(code = 404, message = "请求路径找不到")
    })
    @PostMapping("/changepass")
    public Resp<?> changePassword(@RequestBody @Valid UpdatePasswordReqDTO reqDTO) {
        return Resp.ok("更新成功");
    }

    @ApiOperation(value = "用户登录", notes = "随边说点啥")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "mobile", value = "手机号", required = true, paramType = "query"),
            @ApiImplicitParam(name = "password", value = "密码", required = true, paramType = "query"),
            @ApiImplicitParam(name = "age", value = "年龄", required = true, paramType = "query", dataType = "Integer")
    })
    @PostMapping("/login")
    public Resp<?> login(@RequestParam("mobile") String mobile, @RequestParam("password") String password,
                          @RequestParam("age") Integer age) {
        // TODO
        return Resp.ok();
    }

    @ApiOperation("根据部门Id删除")
    @ApiImplicitParam(name = "depId", value = "部门id", required = true, paramType = "query")
    @GetMapping("/delete")
    public Resp<?> delete(String depId) {
        //TODO
        return Resp.ok(depId);
    }
}
